package cate.common.table.activity.custommade;

import cate.common.table.EExcelNoteField;
import cate.common.table.EExcelRowClass;
import cate.common.table.ERow;
import cate.common.table.XSSFRowWrap;
import easy.java.dev.note.NoteField;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

@EExcelRowClass
public class CustomMadePosRow extends ERow {

    @EExcelNoteField(fieldName = "栏位")
    public byte pos;
    @EExcelNoteField(fieldName = "配置ID")
    public int posGroup;
    @EExcelNoteField(fieldName = "是否固定", defaultValue = "false")
    public boolean stable;
    @EExcelNoteField(fieldName = "限购次数", defaultValue = "1")
    public int limitTimes;
    @EExcelNoteField(fieldName = "重置类型", defaultValue = "0")
    public int resetType;
    @EExcelNoteField(fieldName = "物品消耗", defaultValue = "")
    public String costStr;


    @NoteField("位置 -> 固定奖励")
    public Map<Byte, String> stableRewards = new HashMap<>();
    @NoteField("位置 -> 自选奖励")
    public Map<Byte, String> selectRewards = new HashMap<>();

    @Override
    public void parse(XSSFRowWrap xrw) {
        super.parse(xrw);
        stableRewards.clear();
        selectRewards.clear();
        for (byte i = 1; i <= 8; i++) {
            Byte stable = xrw.getByte(String.format("是否自选%d", i));
            if (stable == null) {
                break;
            }
            String rewardStr;
            if (stable == 0) {
                rewardStr = xrw.getString(String.format("第%d格固定奖励", i));
                if (StringUtils.isNotBlank(rewardStr)) {
                    stableRewards.put(i, rewardStr);
                }
            } else {
                rewardStr = xrw.getString(String.format("格%d自选池", i));
                if (StringUtils.isNotBlank(rewardStr)) {
                    selectRewards.put(i, rewardStr);
                }
            }
        }
    }
}
